package main

import "fmt"

// 类型断言
func main() {
	var a interface{}

	var b = Point{32, 21}

	a = b

	a = a.(Point)

	var c Point
	//类型断言
	c, ok := a.(Point)
	//断言时带检查机制
	if ok == true {
		fmt.Println("convert success")
	}

	fmt.Println(a)

	fmt.Println(c)
	fmt.Println("----------------------------------")
	test1()

}

func test1() {
	var a interface{}

	var b float32 = 23.32
	a = b

	y, ok := a.(float64)
	if ok {
		fmt.Println("convert success")
		fmt.Printf("y的类型是 %T, 值是 %v", y, y)
	} else {
		fmt.Println("convert failed")
	}

	fmt.Println("程序继续执行")
}

type Point struct {
	y int
	x int
}
